package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.Employee;
import com.kaishengit.entity.Project;
import com.kaishengit.service.DocumentService;
import com.kaishengit.util.web.ServletUtil;

public class AddDocument extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		ServletUtil.forward(request, response, "add_document");
	
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		HttpSession session = request.getSession();
		Employee e = (Employee) session.getAttribute("employee");
		Project p = (Project) session.getAttribute("project");
		
		DocumentService service = new DocumentService();
		
		service.save(title,content,e.getId(),p.getId());
		
		ServletUtil.redirect(response, "documentlist.jspx");
		
	}

}
